﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication4
{
    public partial class KheUoc : Form
    {

        private SqlConnection con = new SqlConnection();
        private DataTable dt = new DataTable("KheUoc");
        private SqlDataAdapter da = new SqlDataAdapter();


        private void connect()
        {
            string cn = "Data Source=(local);Initial Catalog=LoanPS;Integrated Security=True";
            try
            {
                con = new SqlConnection(cn);
                con.Open();//mo ket noi

            }
            catch (Exception ex)
            {
                MessageBox.Show("Khong ket noi duoc co so du lieu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void disconnect()
        {
            con.Close();//dong ket noi
            con.Dispose();//giai phong tai nguyen
            con = null;//huy doi tuong

        }

        public KheUoc()
        {
            InitializeComponent();
        }

        private void kheUocBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.kheUocBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.loanPSDataSet);

        }

        private void KheUoc_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'loanPSDataSet.KieuTra' table. You can move, or remove it, as needed.
            this.kieuTraTableAdapter.Fill(this.loanPSDataSet.KieuTra);
            // TODO: This line of code loads data into the 'loanPSDataSet.LaiXuat' table. You can move, or remove it, as needed.
            this.laiXuatTableAdapter.Fill(this.loanPSDataSet.LaiXuat);
            // TODO: This line of code loads data into the 'loanPSDataSet.MucDichVay' table. You can move, or remove it, as needed.
            this.mucDichVayTableAdapter.Fill(this.loanPSDataSet.MucDichVay);
            // TODO: This line of code loads data into the 'loanPSDataSet.HinhthucDamBao' table. You can move, or remove it, as needed.
            this.hinhthucDamBaoTableAdapter.Fill(this.loanPSDataSet.HinhthucDamBao);
            // TODO: This line of code loads data into the 'loanPSDataSet.NhanVien' table. You can move, or remove it, as needed.
            this.nhanVienTableAdapter.Fill(this.loanPSDataSet.NhanVien);
            // TODO: This line of code loads data into the 'loanPSDataSet.DoiTac' table. You can move, or remove it, as needed.
            this.doiTacTableAdapter.Fill(this.loanPSDataSet.DoiTac);
            // TODO: This line of code loads data into the 'loanPSDataSet.KheUoc' table. You can move, or remove it, as needed.
            this.kheUocTableAdapter.Fill(this.loanPSDataSet.KheUoc);
            connect();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            DialogResult d1 = MessageBox.Show("ban chac chan muoc thoat khoi Form Khe Uoc", "thong bao", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (d1 == DialogResult.OK)
                this.Close();
        }

        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                textBox1.Focus();
                MessageBox.Show("Ban chua nhap MaKheUoc", "Thong Bao", MessageBoxButtons.OK);
            }
            else
            {

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "updateKheUoc";
                cmd.Parameters.Add("@MaKheUoc", SqlDbType.NVarChar, 50).Value = textBox1.Text;
                SqlDataReader daReader = cmd.ExecuteReader();
                dt.Load(daReader);
                MessageBox.Show("Complete", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Text = "";
            }
        }
    }
}
